/*
 * @Description:
 * @version:
 * @Author: 潘骏杰
 * @Date: 2021-11-26 14:09:25
 * @LastEditors: 潘骏杰
 * @LastEditTime: 2021-12-02 11:11:36
 */

import CryptoJS from '@/utils/CryptoJS'

export default {
  setItem(name, data) {
    // console.log(data);
    if (typeof data === 'string') {
      return window.localStorage.setItem(name, CryptoJS.encrypt(data))
    } else {
      return window.localStorage.setItem(
        name,
        CryptoJS.encrypt(JSON.stringify(data))
      )
    }
  },
  getItem(name, str) {
    // let obj = window.localStorage.getItem(name);
    // console.log(typeof obj)
    if (window.localStorage.getItem(name)) {
      if (!str) {
        return JSON.parse(CryptoJS.decrypt(window.localStorage.getItem(name)))
      } else {
        return CryptoJS.decrypt(window.localStorage.getItem(name))
      }
    }
  }
}
